package club.twelveblog.tblog.utils;

import club.twelveblog.tblog.common.dto.UserDto;
import club.twelveblog.tblog.entity.User;
import org.springframework.stereotype.Component;

@Component
public class Defence {
    public User defenceInjection(User user){
        String username=user.getUsername();
        String password=user.getPassword();
        String address=user.getAddress();
        String email=user.getEmail();
        String sex=user.getSex();
        User user1=new User();
        user1.setPassword(password.replaceAll(".*([';]+|(--)+).*",""));
        user1.setUsername(username.replaceAll(".*([';]+|(--)+).*",""));
        user1.setAddress(address.replaceAll(".*([';]+|(--)+).*",""));
        user1.setEmail(email.replaceAll(".*([';]+|(--)+).*",""));
        user1.setSex(sex.replaceAll(".*([';]+|(--)+).*",""));
        user1.setBirthday(user.getBirthday());
        return user1;
    }
    public UserDto defenceInjection1(UserDto user){
        String username=user.getUsername();
        String password=user.getPassword();

        UserDto user2=new UserDto();
        user2.setPassword(password.replaceAll(".*([';]+|(--)+).*",""));
        user2.setUsername(username.replaceAll(".*([';]+|(--)+).*",""));

        return user2;
    }
}
